// USER-DEFINED FUNCTIOn
function confirmDelete(id, tab, p, returnurl)
{						
	if (confirm("Are you sure you want to delete")) {  
		ajaxpage('includes/_delete_.php?id='+id+'&tab='+tab, 'pnDetails');
		window.location = 'index.php?p='+p;
	}
}

function goTo(url) {
	document.location = url;
}


/* 
	Ajax
*/
var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
  var page_request = false
  if (window.XMLHttpRequest) // if Mozilla, Safari etc
  page_request = new XMLHttpRequest()
  else if (window.ActiveXObject){ // if IE
    try {
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
      try{
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }
      catch (e){}
    }
  }
  else
    return false
  page_request.onreadystatechange=function(){
    loadpage(page_request, containerid)
  }
  page_request.open('GET', url, true)
  page_request.send(null)
}

// AJAX LOAD PAGE
function loadpage(page_request, containerid){
  if(page_request.readyState != 4) 
    document.getElementById('ajaxheader').innerHTML=
    '<div align="right" style="font-size:9px; font-family:Verdana; font-weigth:bold; margin-top:5px; margin-bottom:-33px;"><img src="ajax-loader.gif"><br />Loading... Please wait...</div>';
  if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
    document.getElementById(containerid).innerHTML=page_request.responseText
    document.getElementById('ajaxheader').innerHTML=null
  }
}

/* 
	Form Validator
*/
function required_field(id, msgtrue, msgfalse) {
	// Init & check
	var a = document.getElementById(id);
	var b = document.getElementById(id+'True');
	var c = document.getElementById(id+'False');
	if (msgtrue == null) msgtrue = 'Validated!';
	if (msgfalse == null) msgfalse = 'Invalid data.';
	
	// Hide all messages
	b.style.display = 'none';
	c.style.display = 'none';
	// Start checking
	if (a.value.length == 0) {		
		b.style.display = 'none';
		c.innerHTML = msgfalse;
		c.style.display = 'block';
		return false;
	}
	else {
		b.style.display = 'block';
		b.innerHTML = msgtrue;
		c.style.display = 'none';
		return true;
	}
}

function textarea_required_field(id, msgtrue, msgfalse) {
	// Init & check
	var a = document.getElementById(id);
	var b = document.getElementById(id+'True');
	var c = document.getElementById(id+'False');
	if (msgtrue == null) msgtrue = 'Validated!';
	if (msgfalse == null) msgfalse = 'Invalid data.';
	
	// Hide all messages
	b.style.display = 'none';
	c.style.display = 'none';
	// Start checking
	if (a.innerHTML.length == 0) {		
		b.style.display = 'none';
		c.innerHTML = msgfalse;
		c.style.display = 'block';
		return false;
	}
	else {
		b.style.display = 'block';
		b.innerHTML = msgtrue;
		c.style.display = 'none';
		return true;
	}
}